/*
data :{key:value}
success:{func:func, params}
fail: just as same as success
实现 数据的ajax操作
*/
export default function(data, method, action,success,fail){

  let form = new FormData();

  for(let key in data){
    form.append(key,data[key]);
  }
  let xhr = new XMLHttpRequest();
  // method: POST,GET
  try{
    xhr.open(method, action);


    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4 &&
            xhr.status == 200) {
            //xhr.responseText

              if(success){
                success.func(xhr,success.params);
              }
        }
    }
  }
  catch(e){


  }


  xhr.send(form);

}
